#ifndef SFTP_CLIENT_H
#define SFTP_CLIENT_H

#include <mutex>
#include <QFile>
#include <QObject>
#include "curl/curl.h"

class TaskPool;

class SftpClient : public QObject
{
	Q_OBJECT

public:
	explicit SftpClient(CURLM* curlm, int concurrency = 5, QObject* parent = nullptr);

	void setLoginInfo(const QString& hostname, const QString& hostport, const QString& username, const QString& password);

	void downloadDir(const QString& remote, const QString& local, const QString& filter);
	void downloadFile(const QString& remote, const QString& filePath);

	void uploadDir(const QString &remote, const QString& localDir, const QString &fiter);
	void uploadFile(const QString &remote, const QString &filePath);

	QQueue<QString> exploreLocalFolderAndFiles(const QString& local, const QString& filter);

	QQueue<QString> exploreSftpFolderAndFiles(const QString& remote, const QString& filter);

private:
	void exploreLocalFolderAndFiles(const QString& local, const QString& filter, QQueue<QString>* folderAndFiles);

private:
	const int  m_concurrency;
	std::mutex m_mutex;
	CURLM*     m_curlm;
	QString m_hostname;
	QString m_hostport;
	QString m_username;
	QString m_password;
};


#endif //  SFTP_CLIENT_H

